package com.syx.system.Controller.sysuser;

import com.syx.commoncore.Constant.HttpConstants;
import com.syx.commoncore.Model.Result;
import com.syx.system.Model.sysUser.DTO.LoginDTO;
import com.syx.system.Model.sysUser.DTO.SysUserSaveDTO;
import com.syx.system.Model.sysUser.VO.LoginUserVO;
import com.syx.system.Service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/sysUser")
@RestController
@Tag(name = "管理员接口")
public class SysUserController {
    @Resource
    private ISysUserService iSysUserService;


    @RequestMapping (value = "/login"/*,produces = "application/json"*/)
    public Result login(@RequestBody LoginDTO loginDTO){
        return iSysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());


    }
    //获取用户信息
    @RequestMapping("info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return iSysUserService.info(token);
    }





    @PostMapping("/add")
    //描述接口操作的
    @Operation(summary = "新增管理员",description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已经存在")
    @ApiResponse(responseCode = "3000",description = "操作失败")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        //dto是用来接收前端的数据的，dto中包含只需要前端传输的字段，vo实际上就是返回给前端的数据，有时候返回给前端并不是我们想要的数据，需要进行修改，那么就要进行使用vo
        return iSysUserService.add(sysUserSaveDTO);


    }
    //退出登录功能
    @Operation(summary = "退出登录",description = "通过token退出登录")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已经存在")
    @ApiResponse(responseCode = "3000",description = "操作失败")
    @DeleteMapping("/logout")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return iSysUserService.logout(token);


    }








}
